package com.ycl.controller;

import com.alibaba.fastjson.JSONObject;
import com.ycl.common.Icon;
import com.ycl.common.YChatConstant;
import com.ycl.runnable.ServerRunnable;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.charset.StandardCharsets;

//服务端
public class ServerController {
    /**
     *
     * @param args
     */
    public static void main(String[] args){
        try {
            Icon.loginIcon(9);
            ServerSocket serverSocket = new ServerSocket(YChatConstant.Port);
            new Thread(new ServerRunnable(serverSocket)).start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 给客户端发送消息
     */
    public static void sendInfo(Socket socket, JSONObject info) throws Exception{
        //传输utf8格式，防止乱码
        socket.getOutputStream().write(info.toJSONString().getBytes(StandardCharsets.UTF_8));
    }
}
